// components/tabs/index.js
const { windowWidth } = wx.getSystemInfoSync()

Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		isVisible: {
			type: Boolean,
			value: true
		},
		categories: {
			type: Array,
			value: []
		},
		currentId: {
			type: Number,
			value: 0
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		scrollLeft: 0
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		switchTab(e) {
			// console.log(windowWidth, e)
			const left = e.detail.x
			const offsetLeft = e.target.offsetLeft
			this.setData({
				scrollLeft: offsetLeft - windowWidth / 2
			})
			var myEventDetail = {
				id: e.currentTarget.dataset.id
			} // detail对象，提供给事件监听函数
			this.triggerEvent('switch', myEventDetail)
		}
	},
	attached() {
		console.log(this.data.categories)
	}
})
